﻿@{
    ViewData["Title"] = "修改转移调拨";
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <!-- 给容器追加 class="layui-form-pane"，即可显示为方框风格 -->
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">转移单编号</label>
            <div class="layui-input-block">
                <input type="text" name="TransferCode" id="TransferCode" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">转移单名称</label>
            <div class="layui-input-block">
                <input type="text" name="TransferName" id="TransferName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">转移单类型</label>
            <div class="layui-input-block">
                <select name="TransferType" id="TransferType" lay-verify="required">
                    <option value="">请选择</option>
                    <option value="外部转移">外部转移</option>
                    <option value="内部转移">内部转移</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">移出仓库</label>
            <div class="layui-input-block">
                <input type="text" name="FromWarehouseName" id="FromWarehouseName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">移入仓库</label>
            <div class="layui-input-block">
                <input type="text" name="ToWarehouseName" id="ToWarehouseName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">转移日期</label>
            <div class="layui-input-inline layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-date"></i>
                </div>
                <input type="text" name="TransferDate" id="TransferDate" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            </div>

        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">单据状态</label>
            <div class="layui-input-block">
                <input type="text" name="Status" id="Status" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-form-item">
                <button class="layui-btn" lay-submit lay-filter="demo2">修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

    </form>

    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script>
    <script>
        layui.use(['form'], function () {
            var layer = layui.layer;
            var form = layui.form;
            var laydate = layui.laydate;

            // 日期
            laydate.render({
                elem: '#TransferDate'
            });

            //反填
            function generateVendorCode() {
                $("#TransferCode").val(parent.TransferCode);
                $("#TransferName").val(parent.TransferName);
                $("#TransferType").val(parent.TransferType);
                $("#FromWarehouseName").val(parent.FromWarehouseName);
                $("#ToWarehouseName").val(parent.ToWarehouseName);
                $("#TransferDate").val(parent.TransferDate);
                $("#Status").val(parent.Status);
            }
            generateVendorCode()


            // 表单提交事件
            form.on('submit(demo2)', function (data) {
                var field = data.field; // 获取表单字段值
                console.log(field);
                var UpdateDto = {
                    //获取表单
                    TransferCode: field.TransferCode,
                    TransferName: field.TransferName,
                    TransferType: field.TransferType,
                    FromWarehouseName: field.FromWarehouseName,
                    ToWarehouseName: field.ToWarehouseName,
                    TransferDate: field.TransferDate,
                    Status: field.Status,

                    //数据库值
                    Id : parent.Id ,
                    TransferId : parent.TransferId ,
                    FromWarehouseId : parent.FromWarehouseId ,
                    FromWarehouseCode : parent.FromWarehouseCode ,
                    ToWarehouseId : parent.ToWarehouseId ,
                    ToWarehouseCode : parent.ToWarehouseCode ,
                    Remark : parent.Remark ,
                    CreateBy : parent.CreateBy ,
                    CreateTime : parent.CreateTime ,
                }
                $.ajax({
                    url: "/Meng/UpdateTransfer",
                    type: "get",
                    async: true,
                    data: UpdateDto,
                    contentType: "application/json",
                    success: res => {
                        if (res == 1) {
                            alert("修改成功")
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }
                        else {
                            console.log(res.code)
                            alert("修改失败")
                        }
                    }
                });
                console.log("1")
                return false; // 阻止默认 form 跳转
            });
        });

    </script>

</body>
</html>